<?php

	global $HTTP_GET_VARS;
	global $HTTP_POST_VARS;
	global $account;
	global $account_state;
	global $error;
	global $sql_row, $sql, $sql_total;

	$game = $_GET['game'];
	
	if (strpos($game,"/",0) !== false||strpos($game,"\\",0) !== false)
	{
		die("Warning: Possible hacking attempt detected. Aborted.");	
	}
	
	if (file_exists('scripts/'.$game.'.php'))
	{
		include_once('scripts/'.$game.'.php');
		
		if ( $account_state == 0)
		{
			error_redirect('Please log in to reach this page.',ERROR_LOGIN_REQUIRED,'../distribution/?action=editgame&game='.$game);
			die();
		}
		if ($account['id'] != $owner[$game] && $account['admin'] != 1)
		{
			error_redirect('You are not allowed to view this page.',ERROR_GENERAL);
			die();
		}
		
		$keys			=	makedefaultkeywords();		
		dopage('Upload_StartRows',$keys);
		$keys			=	makedefaultkeywords();
		$keys			=	makekeywords('name','Editing '.$game.'!',$keys);
		$keys			=	makekeywords('desc','Change everything about '.$game.', logo, maps, passwords, everything!',$keys);
		$keys			=	makekeywords('thumburl_100px',uploadid(1652),$keys);
		dopage('upload_row',$keys);			
		$keys			=	makedefaultkeywords();		
		dopage('Upload_EndRows',$keys);
		
				$num_maps	=	count($progress_id_to_value[$game]);		
		$maps		=	'';
		
		for ($i = 0; $i < $num_maps; $i++)
		{	
			$maps	.=	$progress_id_to_value[$game][$i];
			if ($i != $num_maps-1 )
			{
				$maps	.=	"\n";
			}			
		}	
		
		
		$keys			=	makedefaultkeywords();
		$keys			=	makekeywords('Game',html2text($game),$keys);
		$keys			=	makekeywords('LogoID',html2text($logo_100x100[$game]),$keys);
		$keys			=	makekeywords('About',html2text($about[$game]),$keys);
		$keys			=	makekeywords('OwnerName',html2text(id2username($owner[$game])),$keys);
		$keys			=	makekeywords('DownloadLink',html2text($download_link[$game]),$keys);
		$keys			=	makekeywords('MapsList',html2text($maps),$keys);
		$keys			=	makekeywords('NumMaps',$num_maps+2,$keys);
		$keys			=	makekeywords('MISScript',str_replace("\r\n","<br />\r\n",html2text(file_get_contents('scripts/'.$game.'.mis'))),$keys);		
		dopage('Distribution_EditGame',$keys);
				
			
	}
	else
	{	
		output('<p><b class="text_big">'.html2text($game).'</b><br />Sorry this game is not supported by Maxsi Distribution.</p>');		
	}
	

?>